package com.atgm.mall.gmmailmember.controller;

import com.atgm.common.utils.R;
import com.atgm.mall.gmmailmember.entity.MemberWishEntity;
import com.atgm.mall.gmmailmember.service.MemberWishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gmmallmember/memberwish")
public class MemberWishController {

    @Autowired
    private MemberWishService memberWishService;

    @PostMapping("/addWish")
    public R addMemberWish(@RequestBody MemberWishEntity entity) {
        Long id = memberWishService.insertMemberWish(entity);
        return R.ok().setData(String.valueOf(id));
    }

    @DeleteMapping("/deleteWish/{id}")
    public R deleteWish(@PathVariable("id") Long id) {
        memberWishService.deleteWishById(id);
        return R.ok();
    }

    @DeleteMapping("/deleteWish/{gameId}/{memberId}")
    public R deleteWishBygameIdAndMemberId(@PathVariable("gameId") Long gameId, @PathVariable("memberId") Long memberId) {
        memberWishService.deleteWishInfo(gameId, memberId);
        return R.ok();
    }

    @GetMapping("/getWishGameIds/{memberId}")
    public R getWishGameIds(@PathVariable("memberId") Long memberId) {
        List<Long> list = memberWishService.queryWishGameIds(memberId);
        return R.ok().setData(list);
    }

    /**
     * 用户是否添加该游戏心愿单
     * @param gameId
     * @param memberId
     * @return
     */
    @GetMapping("/isWished/{gameId}/{memberId}")
    public R isWished(@PathVariable("gameId") Long gameId, @PathVariable("memberId") Long memberId) {
        Integer flag = memberWishService.checkIsWished(gameId, memberId);
        return R.ok().setData(flag);
    }

}
